Introduce RECLAIM_INIT_CODE build flag
authorDaniel Boulby <[email protected]>
Tue, 18 Sep 2018 10:45:51 +0000 (11:45 +0100)
committerAntonio Nino Diaz <[email protected]>
Wed, 3 Oct 2018 10:47:30 +0000 (11:47 +0100)
This patch introduces a build flag "RECLAIM_INIT_CODE" to mark boot time
code which allows platforms to place this memory in an appropriate
section to be reclaimed later. This features is primarily targeted for
BL31. Appropriate documentation updates are also done.

Change-Id: If0ca062851614805d769c332c771083d46599194
Signed-off-by: Daniel Boulby <[email protected]>
Makefile
docs/firmware-design.rst
include/lib/libc/cdefs.h
make_helpers/defaults.mk

index 23a1b0a372ae25f057b56abf83ce86390da1f57f..d487eae7f2427ef8074fab4e36efaa2b5be3a46a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -634,6 +634,7 @@ $(eval $(call add_define,PSCI_EXTENDED_STATE_ID))
 $(eval $(call add_define,RAS_EXTENSION))
 $(eval $(call add_define,RESET_TO_BL31))
 $(eval $(call add_define,SEPARATE_CODE_AND_RODATA))
+$(eval $(call add_define,RECLAIM_INIT_CODE))
 $(eval $(call add_define,SMCCC_MAJOR_VERSION))
 $(eval $(call add_define,SPD_${SPD}))
 $(eval $(call add_define,SPIN_ON_BL1_EXIT))
index 79bdec98f9cd81e13f79476eb1385c1b7178190e..7cc74855ded3e3db0054a806aa9cb2cc1e06f33d 100644 (file)
@@ -2336,6 +2336,29 @@ implement:
 
    SUBSCRIBE_TO_EVENT(foo, foo_handler);
 
+
+Reclaiming the BL31 initialization code
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+A significant amount of the code used for the initialization of BL31 is never
+needed again after boot time. In order to reduce the runtime memory
+footprint, the memory used for this code can be reclaimed after initialization
+has finished and be used for runtime data.
+
+The build option ``RECLAIM_INIT_CODE`` can be set to mark this boot time code
+with a ``.text.init.*`` attribute which can be filtered and placed suitably
+within the BL image for later reclaimation by the platform. The platform can
+specify the fiter and the memory region for this init section in BL31 via the
+plat.ld.S linker script. For example, on the FVP, this section is placed
+overlapping the secondary CPU stacks so that after the cold boot is done, this
+memory can be reclaimed for the stacks. The init memory section is initially
+mapped with ``RO``, ``EXECUTE`` attributes. After BL31 initilization has
+completed, the FVP changes the attributes of this section to ``RW``,
+``EXECUTE_NEVER`` allowing it to be used for runtime data. The memory attributes
+are changed within the ``bl31_plat_runtime_setup`` platform hook. The init
+section section can be reclaimed for any data which is accessed after cold
+boot initialization and it is upto the platform to make the decision.
+
 Performance Measurement Framework
 ---------------------------------
 
index b1d10ccce5340aae687a520e36db28793ac1303b..0d0072254ae0b439520705ebd52e901c41245f69 100644 (file)
 #define __unused       __attribute__((__unused__))
 #define __aligned(x)   __attribute__((__aligned__(x)))
 #define __section(x)   __attribute__((__section__(x)))
+#if RECLAIM_INIT_CODE
+/*
+ * Add each function to a section that is unique so the functions can still
+ * be garbage collected
+ */
+#define __init         __section(".text.init." __FILE__ "." __XSTRING(__LINE__))
+#else
+#define __init
+#endif
 
 #define __printflike(fmtarg, firstvararg) \
                __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
index 7df4cd286d145f1eec12691ff5986e362501aec4..435de20e3edc36ea6b0b6e7e1187c6e0d0831c6f 100644 (file)
@@ -146,6 +146,10 @@ SDEI_SUPPORT               := 0
 # platform Makefile is free to override this value.
 SEPARATE_CODE_AND_RODATA       := 0
 
+# If the BL31 image initialisation code is recalimed after use for the secondary
+# cores stack
+RECLAIM_INIT_CODE              := 0
+
 # Default to SMCCC Version 1.X
 SMCCC_MAJOR_VERSION            := 1